home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 123_01.zip / UTIL.BDS < prev    next >
Text File  |  1993-06-07  |  3KB  |  219 lines

  1. /*
  2.     Supplementary routines for archive program
  3.     Adapted from supp.bds May 4, 1982 OSCAR GOLDMAN
  4.  
  5.     source:  ar1/util.bds
  6.     version: February 24, 1983
  7. */
  8.  
  9. #include "bdscio.h"
  10. #include "dio.h"
  11. #include "date.h"
  12.  
  13. #define EOS 0
  14.  
  15.  
  16. /* Print "can't open <filename>" and exit. */
  17.  
  18. cant(filename)
  19. char *filename;
  20. {
  21.     fprintf(STD_ERR, "can not open %s\n", filename);
  22.     exit();
  23. }
  24.  
  25.  
  26. /* Print an error message and exit. */
  27.  
  28. error(message)
  29. char *message;
  30. {
  31.     fprintf(STD_ERR, "%s\n", message);
  32.     exit();
  33. }
  34.  
  35.  
  36. /*
  37.     Get a line from the indicated device.
  38.     Terminate the line with a NEWLINE character.
  39.     Return the number of characters INCLUDING the NEWLINE.
  40.     Thus, return 0 on end-of-file.
  41. */
  42.  
  43. int
  44. get_line (str, fd)
  45. char *str;
  46. int fd;
  47. {
  48.     /* abort on control-c at console */
  49.     chkkey();
  50.  
  51.     if (fgets(str, fd) == 0) {
  52.         return 0;
  53.     }
  54.     else {
  55.         return strlen(str);
  56.     }
  57. }
  58.  
  59.  
  60. /*
  61.     Return pointer to current time and date.
  62.     This version just prompts the console for a string and returns it.
  63.     Modify this if desired to make use of clock or calendar hardware.
  64.     Just make sure the sting fits into sys_date (see date.h).
  65. */
  66.  
  67. char *
  68. getnow ()
  69. {
  70.     char *static;
  71.  
  72.     /* kludge because BDS C lacks true static variables */
  73.     static = "";
  74.  
  75.     /*
  76.         get the date and time from the console only on the FIRST
  77.         call to this routine.  Whatever is typed will be put
  78.         into the header fields of the archive.
  79.     */
  80.     
  81.     if (*static == 0) {
  82.         *static = 1;
  83.         fprintf(DEV_TTY, "\nEnter mm/dd/yy <2 spaces> hh:mm:ss  \n");
  84.         gets(sys_date);
  85.         if (sys_date [0] == EOS) {
  86.             sys_date [0] == '\n';
  87.             sys_date [1] == EOS;
  88.         }
  89.     }
  90.     return sys_date;
  91. }
  92.  
  93.  
  94. /*
  95.     Get nonblank word from in[] into out[];
  96.     Return the number of characters scanned over.
  97. */
  98.  
  99. char *
  100. getwrd (in, out)
  101. char *in, *out;
  102. {
  103.     int count;
  104.  
  105.     /* skip blanks and keep count */    
  106.     count = 0;
  107.     while (*in == ' ' || *in == '\t') {
  108.         in++;
  109.         count++;
  110.     }
  111.  
  112.     while (*in != EOS && *in != ' ' && *in != '\t' && *in != '\n') {
  113.         *out++ = *in++;
  114.         count++;
  115.     }
  116.     *out = EOS;
  117.     return count;
  118. }
  119.  
  120.  
  121. /* Convert a string to all lower case */
  122.  
  123. lower(string)
  124. char *string;
  125. {
  126.     while (*string) {
  127.         *string = tolower( (*string) & 0x7f);
  128.         string++;
  129.     }
  130. }
  131.  
  132.  
  133. /*
  134.     Create a temporary file name of the form TEMP.$n$
  135.     for a given value of n
  136. */
  137.  
  138. mkunik(n,name)
  139. int    n;
  140. char *name;
  141. {
  142.     strcpy(name, "TEMP.$ $");
  143.     name [6] = n%10 + '0';
  144. }
  145.  
  146.  
  147. /*
  148.     Put a line to the indicated device.
  149.     Do NOT end the line with a NEWLINE character.
  150. */
  151.  
  152. put_line (line, fd)
  153. char *line;
  154. int fd;
  155. {
  156.     fprintf (fd, "%s", line);
  157. }
  158.  
  159.  
  160. /* Print a warning message but continue. */
  161.  
  162. remark(message)
  163. char *message;
  164. {
  165.     fprintf(STD_ERR, "%s\n", message);
  166. }
  167.  
  168.  
  169. /*
  170.     Skip blanks and tabs.
  171.     Return pointer to next nonblank, non tab character.
  172. */
  173.  
  174. char *
  175. skipbl(line)
  176. char *line;
  177. {
  178.     while (*line == ' ' || *line == '\t') {
  179.         line++;
  180.     }
  181.     return line;
  182. }
  183.  
  184.  
  185. /*
  186.     Saves a string somewhere, using dynamic storage.
  187.     return the pointer to location.
  188. */
  189.  
  190. strsav (s)
  191. char *s;
  192. {
  193.     int    j;
  194.     char    *p;
  195.  
  196.     j = 0;
  197.     p = alloc(strlen(s) +1);    /* store the string here */
  198.     if (p == 0) {
  199.         error("in strsav:  no more dynamic space.");
  200.     }
  201.  
  202.     strcpy(p,s);
  203.     return p;
  204. }
  205.  
  206.  
  207. /* Convert a string to all upper case (for file system) */
  208.  
  209. upper(string)
  210. char *string;
  211. {
  212.     while (*string) {
  213.         *string = toupper( (*string) & 0x7f);
  214.         string++;
  215.     }
  216. }
  217. ystem) */
  218.  
  219. upper(strin